﻿using Customer.Domain;
using Customer.Infrstructre.FinanceManager;
using Customer.Read.API.Applcation.Command.FinanceTypeCommand;
using MediatR;

namespace Customer.Read.API.Applcation.CommandHandler.FinanceTypeCommandHandler
{
    /// <summary>
    /// 显示财务类别
    /// </summary>
    public class SelectFinanceTypeCommandHandler:IRequestHandler<SelectFinanceTypeCommand,List<FinanceType>>
    {
        private readonly IFinanceTypeRepository _financeRepository;

        public SelectFinanceTypeCommandHandler(IFinanceTypeRepository financeRepository)
        {
            _financeRepository = financeRepository;
        }

        public async Task<List<FinanceType>> Handle(SelectFinanceTypeCommand request, CancellationToken cancellationToken)
        {
            var res = (await _financeRepository.GetAllAsync()).Where(x=>x.Office_Id==request.Office_Id  && x.IsDel==false);
            if (!string.IsNullOrEmpty(request.FinanceTypeName))
            {
                res = res.Where(x => x.FinanceTypeName.Contains(request.FinanceTypeName)).ToList();
            }
            return res.ToList();
        }
    }
}
